package psn.zjk.springboot.web.config;

import org.springframework.context.annotation.Bean;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import psn.zjk.springboot.web.interceptor.PermissionInterceptor;
import psn.zjk.springboot.web.servlet.i18n.MyLocaleResolver;

/** 在自动注入配置的基础上增加扩展，用@Configuration注解自己的类，且项目里不能有@EableWebMvc注解 张骏凯 2020年1月31日 */
//@Configuration
public class WebAutoConfigurationExtendition implements WebMvcConfigurer {

    @Override public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("dashboard");
        registry.addViewController("/index.html").setViewName("dashboard");
    }

    @Bean public LocaleResolver localeResolver() {
        return new MyLocaleResolver();
    }

    /**
     * 自定义内嵌servlet容器：undertow不支持jsp，如果只是修改端口之类的配置返回WebServerFactoryCustomizer即可，替换容器只需引入相应依赖即可@Title: jettyWebServerFactoryCustomizer
     * 自动配置实现，查看EmbeddedWebServerFactoryCustomizerAutoConfiguration
     * @Description:
     * @return
     * @author 张骏凯
     * @created 2020年2月8日 下午7:46:08
     */

    //	@Bean
    //	public WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> jettyWebServerFactoryCustomizer() {
    //		ServerProperties serverProperties = null;
    //		Environment environment = null;
    //		//容器类型查看WebServerFactoryCustomizer的实现类
    //		return new JettyWebServerFactoryCustomizer(environment, serverProperties);
    //	}
    @Override public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new PermissionInterceptor()).addPathPatterns("/**")
                .excludePathPatterns("/index.html", "/", "/login");
    }
}
